/*
 * =====================================================================================
 *
 *       Filename:  socket.hpp
 *
 *    Description:  
 *
 *        Version:  0.1a
 *        Created:  17.05.2012 21:52:41
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Waldemar Gorbunov, 
 *   Organization:  
 *
 * =====================================================================================
 */

#ifndef SOCKET_HPP_
#define SOCKET_HPP_

#define MAXCONN 1024
#define MAXRECV 4096
#define MAXSEND 4096
#ifndef SOCKET
#define SOCKET int
#endif
#ifndef closesocket
#define closesocket close
#endif
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>

#include "globals.hpp"
#include "config.hpp"

#include <fcntl.h>
#include <cstdlib>
#include <cstring>

namespace Drosera {

class Socket {

	public:
		Socket ( void );
		virtual ~Socket ( void );

		const SOCKET& getSocket ( void );
		const SOCKET& getFileSocket ( void );
		virtual bool sendSocket ( std::string& );
		virtual int recvSocket ( std::string& );
		virtual SOCKET acceptSocket ( SOCKET& );
		std::string& getSocketIp ( void );
		
		virtual bool bindSocket ( unsigned int );
		virtual bool listenSocket ( void );
		bool createSocket ( void );
		virtual bool initSocket ( void );

	private:
		SOCKET m_sock, m_sock_file;
		struct sockaddr_in m_addr;
		std::string m_ip;

	protected:
		void setSocket ( SOCKET );
		void setSocketFile ( SOCKET );
		void setIp ( void );

};
}
#endif

